//
//  FCLocalUserHelper.m
//  FundChain
//
//  Created by 肖浩然的mac on 2018/2/14.
//  Copyright © 2018年 RUIXIN. All rights reserved.
//

#import "FCLocalUserHelper.h"
#import "FCLeftBarVC.h"
#import "XLSlideMenu.h"
#import "FCBaseNavigationVC.h"
#import "FCHomeVC.h"
#import<CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonCryptor.h>
@implementation FCLocalUserHelper
//网络监听
+ (void)hasNetwork:(void(^)(bool has))hasNet
{
    //创建网络监听对象
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    //开始监听
    [manager startMonitoring];
    //监听改变
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
            case AFNetworkReachabilityStatusNotReachable:
                hasNet(NO);
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
            case AFNetworkReachabilityStatusReachableViaWiFi:
                hasNet(YES);
                break;
        }
    }];
    //结束监听
    [manager stopMonitoring];
}
#pragma mark - 保存XID
+ (void)saveXidStr:(NSString *)xidStr {
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef setObject:xidStr forKey:@"xidStr"];
    [userDef synchronize];
}

+ (NSString*)getXidStr {
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    NSString *resetXidStr = [userDef objectForKey:@"xidStr"];
    NSString *res = [NSString stringWithFormat:@"%@",resetXidStr];
    if (kStringIsEmpty(res)) {
        res = @"";
    }
    return res;
}

// 清空
+ (void)cleanXidStr {
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef removeObjectForKey:@"xidStr"];
}
//保存banner天滑动时对应的wallId
+(void)saveDidScroll:(NSString*)walletId{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef setObject:walletId forKey:@"bannerWalletId"];
    [userDef synchronize];
    
}
//获取banner天滑动时对应的wallId
+(NSString*)getDidScrollWallId{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    NSString *walletIdStr = [userDef objectForKey:@"bannerWalletId"];
    if ([walletIdStr isEqualToString:@"0"]) {
        return @"1001";
    }
    return walletIdStr;
}
#pragma mark - 保存token
+ (void)saveTokenStr:(NSString *)tokenStr{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef setObject:tokenStr forKey:@"tokenStr"];
    [userDef synchronize];
}
+ (NSString*)getTokenStr{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    NSString *resetTokenStr = [userDef objectForKey:@"tokenStr"];
    if (kStringIsEmpty(resetTokenStr)) {
        resetTokenStr = @"";
    }
    return resetTokenStr;
}
#pragma mark - 保存登陆状态(1是登陆,0是没登陆)
+(void)saveLoginStates:(NSString*)loginState{
    
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef setObject:loginState forKey:@"loginState"];
    [userDef synchronize];
    
}
+ (NSString*)getLoginState{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    NSString *loginState = [userDef objectForKey:@"loginState"];
    if (kStringIsEmpty(loginState)) {
        loginState = @"";
    }
    return loginState;
}
+(void)saveIsMainVC:(NSString*)mainStatus{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef setObject:mainStatus forKey:@"mainStatus"];
    [userDef synchronize];
}
+(NSString*)getMainStatus{
    
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    NSString *mainStatus = [userDef objectForKey:@"mainStatus"];
    if (kStringIsEmpty(mainStatus)) {
        mainStatus = @"";
    }
    return mainStatus;
}
+(void)cleanLoginState{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef removeObjectForKey:@"loginState"];
}
// 清空
+ (void)cleanTokenStr{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef removeObjectForKey:@"tokenStr"];
}

#pragma mark - 保存时间格式
+ (void)saveTimeFormatIDStr:(NSString *)timeFormatID {
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef setObject:timeFormatID forKey:@"TimeFormatIDStr"];
    [userDef synchronize];
}

+ (NSString*)getTimeFormatIDStr {
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    NSString *resetPasswordStr = [userDef objectForKey:@"TimeFormatIDStr"];
    if (kStringIsEmpty(resetPasswordStr)) {
        resetPasswordStr = @"0";
    }
    return resetPasswordStr;
}
//时间戳转英文日期
+ (NSString *)changetimeIntervalData:(NSString *)timeInterval {
    
    NSTimeInterval time = [timeInterval integerValue];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [formatter setLocale:locale];
    [formatter setDateFormat:@"dd MMM"];
    NSString * retureTime = [formatter stringFromDate:date];
    return retureTime;
}

//时间戳转中文日期
+ (NSString *)changetimeIntervalChineseData:(NSString *)timeInterval {
    
    NSTimeInterval time = [timeInterval integerValue];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CH"];
    [formatter setDateFormat:@"MMM dd"];
//    [formatter setDateStyle:NSDateFormatterMediumStyle];
//    [formatter setTimeStyle:NSDateFormatterNoStyle];
    NSString * retureTime = [formatter stringFromDate:date];
    return retureTime;
}
//根据时间戳返回时间
+ (NSString *)getBabyDetailAge:(NSString *)timeString{
    
    NSTimeInterval time = [timeString doubleValue];
    
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    NSLog(@"date:%@",[detaildate description]);
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
    
    return currentDateStr;
}


+(NSString*)backCurrentTime{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    //设定时间格式,这里可以设置成自己需要的格式
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    //用[NSDate date]可以获取系统当前时间
    
    NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
    
    return currentDateStr;
    
}
+ (NSString *)getBabyDetailAgeWith:(NSString *)date
{
    NSTimeInterval time = [date doubleValue];
    
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    NSLog(@"date:%@",[detaildate description]);
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
    
    return currentDateStr;
}
+(NSString *)compareDate:(NSDate *)date{
    
    NSTimeInterval secondsPerDay = 24 * 60 * 60;
    NSDate *today = [[NSDate alloc] init];
    NSDate *tomorrow, *yesterday;
    
    tomorrow = [today dateByAddingTimeInterval: secondsPerDay];
    yesterday = [today dateByAddingTimeInterval: -secondsPerDay];
    
    // 10 first characters of description is the calendar date:
    NSString * todayString = [[today description] substringToIndex:10];
//    NSString * yesterdayString = [[yesterday description] substringToIndex:10];
//    NSString * tomorrowString = [[tomorrow description] substringToIndex:10];
    
    NSString * dateString = [[date description] substringToIndex:10];
    
    if ([dateString isEqualToString:todayString])
    {
        return @"今天";
    }
    return nil;
}
#pragma mark - 保存注册email
+ (void)saveUserEmailStr:(NSString *)emailStr {
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef setObject:emailStr forKey:@"UserEmail"];
    [userDef synchronize];
}

+ (NSString*)getUserEmailStr {
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    NSString *resetPasswordStr = [userDef objectForKey:@"UserEmail"];
    if (kStringIsEmpty(resetPasswordStr)) {
        resetPasswordStr = @"";
    }
    NSLog(@"getUserEmailStr ==== %@",resetPasswordStr);
    return resetPasswordStr;
}
// 清空
+ (void)cleanUserEmailStr {
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    [userDef removeObjectForKey:@"UserEmail"];
}

//邮箱验证
+ (BOOL)isValidateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z\u4e00-\u9fa5._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    //过滤字符串前后的空格
    NSString *emailAdd = [email stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    emailAdd = [emailAdd stringByReplacingOccurrencesOfString:@" " withString:@""];
    return[emailTest evaluateWithObject:emailAdd];
}
//md5加密
+ (NSString *) md5:(NSString *) input {
    if (!kStringIsEmpty(input)) {
        const char *cStr = [input UTF8String];
        unsigned char digest[CC_MD5_DIGEST_LENGTH];
        CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call
        
        NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
        
        for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
            [output appendFormat:@"%02x", digest[i]];
        
        return  output;
    }else {
        return  nil;
    }
    
}

+ (NSString *) sha1:(NSString *)input
{
    //const char *cstr = [input cStringUsingEncoding:NSUTF8StringEncoding];
    //NSData *data = [NSData dataWithBytes:cstr length:input.length];
    
    NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding];
    
    uint8_t digest[CC_SHA1_DIGEST_LENGTH];
    
    CC_SHA1(data.bytes, (unsigned int)data.length, digest);
    
    NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
    
    for(int i=0; i<CC_SHA1_DIGEST_LENGTH; i++) {
        [output appendFormat:@"%02x", digest[i]];
    }
    
    return output;
}
+(NSMutableArray *)getTimeAndSign{
    
    
    NSMutableArray *arrM = [NSMutableArray arrayWithCapacity:1];
    NSDate* data = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval timeInterval = [data timeIntervalSince1970]*1000;
    //获取时间戳
    NSString *timeString = [NSString stringWithFormat:@"%ld",(long)timeInterval];
    [arrM addObject:timeString];
    NSString * postSign = [NSString stringWithFormat:@"%@%@%@",[FCLocalUserHelper getTokenStr],timeString,[FCLocalUserHelper getXidStr]];
    [arrM addObject:postSign];
   
    return arrM;
}
+ (void)pushMainTabbarController{
    //回到主线程
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // options是动画选项
        [UIView transitionWithView:[UIApplication sharedApplication].keyWindow duration:0.3f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
            BOOL oldState = [UIView areAnimationsEnabled];
            [UIView setAnimationsEnabled:NO];
            //左侧菜单
            
            FCLeftBarVC *leftVC = [[FCLeftBarVC alloc] init];
            FCHomeVC *mainViewController = [FCHomeVC new];
            FCBaseNavigationVC * nav = [[FCBaseNavigationVC alloc] initWithRootViewController:mainViewController];
            
            //创建滑动菜单
            XLSlideMenu *slideMenu = [[XLSlideMenu alloc] initWithRootViewController:nav];
            //设置左右菜单
            slideMenu.leftViewController = leftVC;
            slideMenu.slideEnabled = YES;
            [UIApplication sharedApplication].keyWindow.rootViewController = slideMenu;
            [UIView setAnimationsEnabled:oldState];
        } completion:^(BOOL finished) {
        }];
    });
}

//随机生成一个字符串
+(NSString *)randomStringWithLength:(NSInteger)len
{
    NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    NSMutableString *randomString = [NSMutableString stringWithCapacity: len];
    
    for (NSInteger i = 0; i < len; i++) {
        [randomString appendFormat: @"%C", [letters characterAtIndex: arc4random_uniform([letters length])]];
    }
    
    return randomString;
    
}
//AES加密过程
+(NSString *)aes256_encryptStr:(NSString *)contentStr
{
    const char *cstr = [contentStr cStringUsingEncoding:NSUTF8StringEncoding];
    NSData *data = [NSData dataWithBytes:cstr length:contentStr.length];
    
    //对数据进行加密
    char keyPtr[kCCKeySizeAES256+1];
    bzero(keyPtr, sizeof(keyPtr));
    [@"passAdFinger" getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
    NSUInteger dataLength = [data length];
    size_t bufferSize = dataLength + kCCBlockSizeAES128;
    void *buffer = malloc(bufferSize);
    size_t numBytesEncrypted = 0;
    CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES,kCCOptionPKCS7Padding | kCCOptionECBMode,
                                          keyPtr, kCCKeySizeAES256,
                                          NULL,
                                          [data bytes], dataLength,
                                          buffer, bufferSize,
                                          &numBytesEncrypted);
    if (cryptStatus == kCCSuccess)
    {
        NSData *result = [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
        //base64
        return [result base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    }else
    {
        return nil;
    }
    
}

//AES解密过程
+(NSString *)aes256_decryptStr:(NSString *)contentStr
{
    if (kStringIsEmpty(contentStr))
    {
        return nil;
    }
    NSData *data = [[NSData alloc] initWithBase64EncodedData:[contentStr dataUsingEncoding:NSASCIIStringEncoding] options:NSDataBase64DecodingIgnoreUnknownCharacters];
    
    //对数据进行解密
    char keyPtr[kCCKeySizeAES256+1];
    bzero(keyPtr, sizeof(keyPtr));
    [@"passAdFinger" getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
    NSUInteger dataLength = [data length];
    size_t bufferSize = dataLength + kCCBlockSizeAES128;
    void *buffer = malloc(bufferSize);
    size_t numBytesDecrypted = 0;
    CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES,
                                          kCCOptionPKCS7Padding | kCCOptionECBMode,
                                          keyPtr, kCCKeySizeAES256,
                                          NULL,
                                          [data bytes], dataLength,
                                          buffer, bufferSize,
                                          &numBytesDecrypted);
    if (cryptStatus == kCCSuccess)
    {
        NSData* result = [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
        
        return [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
        
    }else
    {
        return nil;
    }
    
}
#pragma mark - 保存加密后的随机密码和fingerToken拼成的字符串
+ (void)savePasswordFingerToken:(NSString *)passwordFingerToken
{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    
    [userDef setObject:passwordFingerToken forKey:[NSString stringWithFormat:@"%@passwordFingerToken",[FCLocalUserHelper getXidStr]]];
    
    [userDef synchronize];
}

+ (NSString*)getPasswordFingerToken
{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    
    NSString *resetPasswordStr = [userDef objectForKey:[NSString stringWithFormat:@"%@passwordFingerToken",[FCLocalUserHelper getXidStr]]];
    
    if (kStringIsEmpty(resetPasswordStr)) {
        resetPasswordStr = @"";
    }
    
    return resetPasswordStr;
}

+ (NSString*)getPasswordFingerToken:(NSString *)keyStr
{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    NSString *key = [NSString stringWithFormat:@"%@passwordFingerToken",keyStr];
    
    NSString *resetPasswordStr = [userDef objectForKey:[NSString stringWithFormat:@"%@",key]];
    
    if (kStringIsEmpty(resetPasswordStr)) {
        resetPasswordStr = @"";
    }
    return resetPasswordStr;
    
}

// 清空
+ (void)cleanPasswordFingerToken
{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    
    [userDef removeObjectForKey:[NSString stringWithFormat:@"%@passwordFingerToken",[FCLocalUserHelper getXidStr]]];
}
#pragma mark-数据保存
//保存用户信息
+ (void)saveFMDBUserInfoData:(FCUserModel *)userModel{
    
    //插入多条用户数据
    //清空数据库
    if (userModel != nil) {
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].userInfoModel);
        //            执行删除操作
        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
        [dcmd saveChanges];
        
        //创建插入对象
        FMDTInsertCommand *icmd = [[DBSet shared].userInfoModel createInsertCommand];
        //添加要插入的对象集合
        [icmd add:userModel];
        //设置添加操作是否使用replace语句
        [icmd setRelpace:YES];
        //执行插入操作
        [icmd saveChangesInBackground:^{
            NSLog(@"批量数据提交完成");
        }];
    }
}

//保存用户信息
+ (FCUserModel *)getFMDBUserInfoData{
    FMDTSelectCommand *cmd = [[DBSet shared].userInfoModel createSelectCommand];        //设置更新条件
    [cmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        FCUserModel * model = FMDBArr.firstObject;
        return model;
    }else {
        return nil;
    }
}

//获取添加货币种类
+ (void)saveFMDBWalletTypesData:(FCWalletTypesModel *)walletTypes{
    //插入多条用户数据
    //清空数据库
    if (walletTypes != nil) {
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].walletTypesModel);
        //            执行删除操作
        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
        [dcmd saveChanges];
        
        //创建插入对象
        FMDTInsertCommand *icmd = [[DBSet shared].walletTypesModel createInsertCommand];
        //添加要插入的对象集合
        [icmd add:walletTypes];
        //设置添加操作是否使用replace语句
        [icmd setRelpace:YES];
        //执行插入操作
        [icmd saveChangesInBackground:^{
            NSLog(@"批量数据提交完成");
        }];
    }
    
    
}
//保存获取添加货币种类
+ (FCWalletTypesModel *)getFMDBWalletTypesData{
    
    FMDTSelectCommand *cmd = [[DBSet shared].walletTypesModel createSelectCommand];        //设置更新条件
    [cmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        FCWalletTypesModel * model = FMDBArr.firstObject;
        return model;
    }else {
        return nil;
    }
    
}

//保存所有钱包地址
+ (void)saveFMDBAllAddressModelData:(FCAllAddressModel *)allAddress{
    //插入多条用户数据
    //清空数据库
    if (allAddress != nil) {
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].allAddressModel);
        //            执行删除操作
        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
        [dcmd where:@"walletId" equalTo:allAddress.walletId];
        [dcmd saveChanges];
        //创建插入对象
        FMDTInsertCommand *icmd = [[DBSet shared].allAddressModel createInsertCommand];
        //添加要插入的对象集合
        [icmd add:allAddress.mj_keyValues];
        //设置添加操作是否使用replace语句
        [icmd setRelpace:YES];
        //执行插入操作
        [icmd saveChangesInBackground:^{
            NSLog(@"批量数据提交完成");
        }];
    }
    
}
//获取所有钱包地址
+ (FCAllAddressModel *)getFMDBAllAddressData:(NSString *)walletId{
    FMDTSelectCommand *cmd = [[DBSet shared].allAddressModel createSelectCommand];        //设置更新条件
    [cmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    [cmd where:@"walletId" equalTo:walletId];
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        FCAllAddressModel * model = FMDBArr.firstObject;
        return model;
    }else {
        return nil;
    }
    
}
//保存的钱包数据
+ (void)saveFMDBWalletsModelData:(NSArray *)walletsModelArr{
    
    //插入多条用户数据
    //清空数据库
    if (!kArrayIsEmpty(walletsModelArr)) {
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].walletsModel);
        //            执行删除操作
        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
        [dcmd saveChanges];
        
        //创建插入对象
        FMDTInsertCommand *icmd = [[DBSet shared].walletsModel createInsertCommand];
        //添加要插入的对象集合
        [icmd addWithArray:walletsModelArr];
        //设置添加操作是否使用replace语句
        [icmd setRelpace:YES];
        //执行插入操作
        [icmd saveChangesInBackground:^{
            NSLog(@"批量数据提交完成");
        }];
    }
}

//获取钱包数据
+ (NSArray *)getWalletsModelData{
    FMDTSelectCommand *cmd = [[DBSet shared].walletsModel createSelectCommand];        //设置更新条件
    [cmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        return FMDBArr;
    }else {
        return nil;
    }
}
//保存所有货币钱包余额的数组
+(void)saveFMDBAllBalanceModel:(NSArray *)allBalanceModelArr{
    
    //插入多条用户数据
    //清空数据库
    if (!kArrayIsEmpty(allBalanceModelArr)) {
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].balanceModel);
        //            执行删除操作
        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
        [dcmd saveChanges];
        
        //创建插入对象
        FMDTInsertCommand *icmd = [[DBSet shared].balanceModel createInsertCommand];
        //添加要插入的对象集合
        [icmd addWithArray:allBalanceModelArr];
        //设置添加操作是否使用replace语句
        [icmd setRelpace:YES];
        //执行插入操作
        [icmd saveChangesInBackground:^{
            NSLog(@"批量数据提交完成");
        }];
    }
    
}
//获取所有货币钱包余额的数组
+(NSArray*)getAllBalanceModel{
    
    FMDTSelectCommand *cmd = [[DBSet shared].balanceModel createSelectCommand];        //设置更新条件
    [cmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        return FMDBArr;
    }else {
        return nil;
    }
}
//保存各种货币余额信息
+ (void)saveFMDBBalanceModelData:(FCBalanceModel *)balanceModel{
    //插入多条用户数据
    //清空数据库
    if (balanceModel != nil) {
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].balanceModel);
        //            执行删除操作
        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
        [dcmd where:@"walletId" equalTo:balanceModel.walletId];
        [dcmd saveChanges];
        //创建插入对象
        FMDTInsertCommand *icmd = [[DBSet shared].balanceModel createInsertCommand];
        //添加要插入的对象集合
        [icmd add:balanceModel];
        //设置添加操作是否使用replace语句
        [icmd setRelpace:YES];
        //执行插入操作
        [icmd saveChangesInBackground:^{
            NSLog(@"批量数据提交完成");
        }];
    }
}

//获取各种货币余额信息
+ (FCBalanceModel *)getFMDBBalanceData:(NSString *)walletId{
    FMDTSelectCommand *cmd = [[DBSet shared].balanceModel createSelectCommand];        //设置更新条件
    [cmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    [cmd where:@"walletId" equalTo:walletId];
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        FCBalanceModel * model = FMDBArr.firstObject;
        return model;
    }else {
        return nil;
    }
}
#pragma mark - 保存CCH状态(1是显示,0是隐藏)
+(void)saveCCHStatus:(FCCCHStatusModel*)CCHstatuModel{
    //插入多条用户数据
    //清空数据库
    if (CCHstatuModel != nil) {
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].CCHStatusModel);
        //            执行删除操作
//        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
        [dcmd saveChanges];
        //创建插入对象
        FMDTInsertCommand *icmd = [[DBSet shared].CCHStatusModel createInsertCommand];
        //添加要插入的对象集合
        [icmd add:CCHstatuModel];
        //设置添加操作是否使用replace语句
        [icmd setRelpace:YES];
        //执行插入操作
        [icmd saveChangesInBackground:^{
            NSLog(@"批量数据提交完成");
        }];
    }
}
+ (FCCCHStatusModel*)getCCHstatusModel{
    FMDTSelectCommand *cmd = [[DBSet shared].CCHStatusModel createSelectCommand];        //设置更新条件
//    [cmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        FCCCHStatusModel * model = FMDBArr.firstObject;
        return model;
    }else {
        return nil;
    }
}
//保存汇率的点击下标
+(void)saveFMDBExchangeRatesModel:(FCExchangeRatesModel*)exchangeRatesModel{
    //插入多条用户数据
    //清空数据库
    if (exchangeRatesModel != nil) {
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].exchangeRatesModel);
        //            执行删除操作
        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
        [dcmd where:@"walletId" equalTo:exchangeRatesModel.walletId];
        [dcmd saveChanges];
        //创建插入对象
        FMDTInsertCommand *icmd = [[DBSet shared].exchangeRatesModel createInsertCommand];
        //添加要插入的对象集合
        [icmd add:exchangeRatesModel];
        //设置添加操作是否使用replace语句
        [icmd setRelpace:YES];
        //执行插入操作
        [icmd saveChangesInBackground:^{
            NSLog(@"批量数据提交完成");
        }];
    }
    
}

//获取保存的汇率下标
+(FCExchangeRatesModel*)getFMDBExchangeRatesModel:(NSString*)walletId{
    
    FMDTSelectCommand *cmd = [[DBSet shared].exchangeRatesModel createSelectCommand];        //设置更新条件
    [cmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    [cmd where:@"walletId" equalTo:walletId];
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        FCExchangeRatesModel * model = FMDBArr.firstObject;
        return model;
    }else {
        return nil;
    }
}
+(void)deleteFMDBExchangeRatesModel{
    
    
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].exchangeRatesModel);
        //            执行删除操作
        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
//        [dcmd where:@"walletId" equalTo:exchangeRatesModel.walletId];
        [dcmd saveChanges];
    
}
//保存汇率的点击下标的汇率
+(void)saveFMDBCurrentResultModel:(FCCurrentResultModel*)currentResultModel{
    
    //插入多条用户数据
    //清空数据库
    if (currentResultModel != nil) {
        FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].currentResultModel);
        //            执行删除操作
        [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
        [dcmd where:@"walletId" equalTo:currentResultModel.walletId];
        [dcmd saveChanges];
        //创建插入对象
        FMDTInsertCommand *icmd = [[DBSet shared].currentResultModel createInsertCommand];
        //添加要插入的对象集合
        [icmd add:currentResultModel];
        //设置添加操作是否使用replace语句
        [icmd setRelpace:YES];
        //执行插入操作
        [icmd saveChangesInBackground:^{
            NSLog(@"批量数据提交完成");
        }];
    }
    
}
//获取保存的汇率下标的汇率
+(FCCurrentResultModel*)getFMDBCurrentResultModel:(NSString*)walletId{
    
    FMDTSelectCommand *cmd = [[DBSet shared].currentResultModel createSelectCommand];        //设置更新条件
    [cmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    [cmd where:@"walletId" equalTo:walletId];
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        FCCurrentResultModel * model = FMDBArr.firstObject;
        return model;
    }else {
        return nil;
    }
}
+(void)cleanFMDBCurrentResultModel{
    
    FMDTDeleteCommand *dcmd = FMDT_DELETE([DBSet shared].currentResultModel);
    //            执行删除操作
    [dcmd where:@"XID" equalTo:[FCLocalUserHelper getXidStr]];
    //        [dcmd where:@"walletId" equalTo:exchangeRatesModel.walletId];
    [dcmd saveChanges];
}

+ (NSArray *)allUserDefaultValue
{
    FMDTSelectCommand *cmd = [[DBSet shared].userInfoModel createSelectCommand];        //设置更新条件
    
    NSArray * FMDBArr = [cmd fetchArray];
    if (!kArrayIsEmpty(FMDBArr)) {
        
        return FMDBArr;
    }else {
        return nil;
    }
}



@end
